<template>
    <div>
        <van-nav-bar title="添加地址" left-text="返回" left-arrow @click-left="proxy.$leftClick()" />
        <van-address-edit 
        :area-list="areaList" 
        show-delete 
        show-set-default 
        show-search-result
        :search-result="searchResult" 
        :area-columns-placeholder="['请选择', '请选择', '请选择']" 
        @save="onSave"
 />
    </div>
</template>

<script setup lang="ts">
import { getCurrentInstance, ref } from 'vue';
import { areaList } from '@vant/area-data';
import { useRess } from '@/store/ress';
import type { AddressEditInfo,AddressEditSearchItem } from 'vant';
import router from '@/router';

const { proxy }: any = getCurrentInstance()

// 定义k为内置地址的对象索引类型
type k = keyof AddressEditInfo
// 拿到地址的pinia
const store = useRess();

// 定义详细地址变量
let searchResult = ref<AddressEditSearchItem[]>([]);


// 点击保存按钮
let onSave =async (info:AddressEditInfo)=>{
    // 根据pinia的请求 更新地址数据
    await store.fetchAddRess(info);
    // 跳转到地址列表
    router.push({name:'set'})
}
</script>